// noinspection JSUnusedGlobalSymbols

import {Component} from '@angular/core';
import {NgForOf} from "@angular/common";
import {ProductService} from "../service/product.service";
import {ActivatedRoute} from "@angular/router";

@Component({
    selector: 'app-category',
    standalone: true,
    imports: [
        NgForOf
    ],
    templateUrl: './category.component.html',
    styleUrl: './category.component.css'
})
export class CategoryComponent {
    productList: any[] = [];
    categoryId: string | undefined;

    constructor(private productService: ProductService, private route: ActivatedRoute) {
    }

    ngOnInit(): void {
        this.route.queryParams.subscribe(params => {
            this.categoryId = params['categoryId'];
            console.log(this.categoryId);
            this.getProductListByCategory(typeof this.categoryId === "string" ? this.categoryId : "");
        });
    }

    getProductListByCategory(href: string): void {
        this.productService.getProductVO(href)
            .subscribe(products => {
                this.productList = products?.data?.productList;
            });
    }
}
